<template>
	<view>
		<view class="orderBox" v-for="(item,index) in dataList">
			<view class="orderTitle">
				<!-- <span class="one">{{index+1}}</span> -->
				<span class="two">入驻运营方名称：{{item.providerName}}</span>
				<!-- <span class="three">作业中</span> -->
			</view>
			<view class="itemBox">
				<view class="itemContent">
					<view class="itemTitle">状态:</view>
					<view class="itemValue" :style="getUserTypeStyle(item)">{{getUserType(item)}}</view>
				</view>
				<view class="itemContent" v-if="item.auditingStatus === 3 || item.auditingStatus === 0">
					<view class="itemTitle">创建时间:</view>
					<view class="itemValue">{{item.applyTime}}</view>
				</view>
				
				<view class="itemContent" v-if="item.auditingStatus === 1 || item.auditingStatus === 2">
					<view class="itemTitle">审核完成时间:</view>
					<view class="itemValue">{{item.auditingTime}}</view>
				</view>
			</view>
			<view class="btnBox">

				<view v-if="item.auditingStatus === 3" class="lookCompleted" @click="editToMes(item)">
					编辑修改
				</view>
				<view v-if="item.auditingStatus === 3" class="lookClose" @click="confirmDialog(item, 'submit',)">
					提交入驻申请
				</view>
				<view v-if="item.auditingStatus === 3" class="del"  @click="confirmDialog(item, 'del',)">
					删除
				</view>
				<view v-if="item.auditingStatus === 0 || item.auditingStatus === 1" class="lookClose"   @click="editToMes(item, 'viewStatus')">
					查看申请详情
				</view>
				<view v-if="item.auditingStatus === 2" class="lookClose"  @click="confirmDialog(item, 'view',)">
					查看驳回原因
				</view>
				<view v-if="item.auditingStatus === 2" class="lookCompleted" @click="editToMes(item, 'editStatus')">
					重新编辑申请
				</view>
				<view v-if="item.auditingStatus === 2" class="Resubmit" @click="confirmDialog(item, 'submit',)">
					再次提交
				</view>
				
			</view>
		</view>
		<!-- 提示窗示例 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog :type="'info'" cancelText="取消" confirmText="确认" :title="dialogTitle"
				:content="dialogContent" :before-close="true" @confirm="dialogConfirm" @close="dialogClose">
			</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import Api from "@/api/socialized-servce/person-message/entry-management.js";
	export default {
		name: 'Item',
		components: {},
		props: {
			dataList: {
				type: Array,
				default: () => {
					return [];
				},
			},
		},
		data() {
			return {
					formData: {},
					// 处理信息
					dialogContent: '开始后，加工作业将进入待领料状态并生成对应的领料单。',
					dialogTitle: '确定开始领料加工？',
			}
		},
		methods: {
			editToMes(e, x) {
				let params = {
					data: JSON.stringify(e),
					editStatus: x === 'editStatus',
					viewStatus: x === 'viewStatus'
				}
				let url = "/pages/socialized-service/person-message/entry-management/entry-management-add"
				this.$togo(url, params)
			},
			getUserType(row) {
				if (row.auditingStatus === 0) {
					return '待审核'
				} else if (row.auditingStatus === 1) {
					return '审核通过'
				} else if (row.auditingStatus === 2) {
					return '审核未通过'
				} else if (row.auditingStatus === 3) {
					return '待提交'
				}
			},
			getUserTypeStyle(row) {
				if (row.auditingStatus === 0) {
					return 'color: #FF9D00;'
				} else if (row.auditingStatus === 1) {
					return 'color: #2ECD97;'
				} else if (row.auditingStatus === 2) {
					return 'color: #FF6C6C;'
				} else if (row.auditingStatus === 3) {
					return 'color: #2165FF;'
				}
			},
			// 点击处理
			confirmDialog(formData, status, type) {
				this.reportProgressStatus = false;
				this.warehouseStatus = false
				this.formData = {...formData,status:status};
				if (status === 'submit') {
					this.dialogContent = '确定要将入驻申请，发送到业务运营方进行审核吗？';
					this.dialogTitle = '确定提交审核？';
				} else if (status === 'del') {
					this.dialogContent = '确定删除该条数据？';
					this.dialogTitle = '删除';
				} else if (status === 'view') {
					this.dialogContent = formData.auditingRemark;
					this.dialogTitle = '驳回原因';
				}
				this.$refs.alertDialog.open()
			},
			dialogConfirm() {
				if (this.formData.status === 'submit') {
					this.taskprocessmet({
						...this.formData,
						auditingStatus: 0
					}, 'edit', 'get')
				} else if (this.formData.status === 'del') {
					this.taskprocessmet({
						id: this.formData.id
					}, 'del', 'get')
				} else if (this.formData.status === 'ASSIGNED') {
					this.taskprocessmet({
						taskId: this.formData.taskId
					}, 'startJobTask', 'get')
				} else if (this.formData.status === 'PROGRESS') {
					if (this.reportProgressStatus) {
						if (!this.formData.num) return uni.showToast({
							icon: 'none',
							title: '请输入当前加工量！！'
						});
						if (this.formData.num < 0) {
							uni.showToast({
								icon: 'none',
								title: '请勿输入负数！！'
							});
							this.$set(this.formData, 'num', Math.abs(this.formData.num));
							return;
						}
						this.taskprocessmet({
							num: this.formData.num,
							name: this.formData.operatorName,
							personNo: this.formData.operatorPersonNo,
							organizationNo: this.formData.organizationNo,
							taskId: this.formData.taskId,
							productLineId: this.formData.productLineId,
							reportTime: this.goTimeT(new Date()),
						}, 'reportTask', 'post')
					} 
				} else if (['COMPLETED', 'SUSPENDED'].includes(this.formData.status)) {
					if (this.warehouseStatus) {
						this.taskprocessmet({
							taskId: this.formData.taskId
						}, 'generateReceipt', 'get')
					}
				} 
				this.$refs.alertDialog.close();
			},
			// 提交处理信息
			taskprocessmet(formData, api, post_get) {
				Api[api](formData).then(
					res => {
						if (res.code === 200) {
							// 防止错误重置父组件数据
							this.$emit('setpage1num', 1);
							uni.showToast({
								title: '处理成功'
							});
							this.cancel();
						} else {
							uni.showToast({
								title: res.msg || '处理失败',
								icon: 'none'
							});
						}
					});
			},
			dialogClose() {
				this.$refs.alertDialog.close()
				console.log('点击关闭')
			},
			// 点击取消
			cancel() {
				this.formData = {
					// 农事任务id
					agriculturalTaskNo: '',
					// 作业面积
					workingArea: '',
					// 投入量
					workload: '',
					// 物料损耗
					loss: '',
					// 作业结果
					remark: '',
					startDate: '开始时间',
					endDate: '结束时间',
					completeindex: 0
				};
				this.$refs.alertDialog.close();
			},
		}
	}
</script>

<style lang="scss" scoped>
	.orderBox {
		width: 100%;
		// min-height: 460rpx;
		background-color: #ffffff;
		padding: 12rpx 14rpx 20rpx;
		box-sizing: border-box;
		margin: 0rpx auto;
		margin-top: 30rpx;
		left: 0rpx;
		top: 0rpx;
		width: 684rpx;
		opacity: 1;
		border-radius: 16rpx;
		background: rgba(255, 255, 255, 1);
		box-shadow: 0rpx 0rpx 12rpx rgba(0, 0, 0, 0.05);

		.orderTitle {
			height: 42rpx;
			font-size: 26rpx;
			font-weight: bold;
			letter-spacing: 0rpx;
			line-height: 42rpx;
			color: rgba(39, 39, 39, 1);
			text-align: left;
			display: flex;
			justify-content: flex-start;

			.one {
				margin-left: 10rpx;
			}

			.two {
				// width: calc(100% - 10rpx);
				width: calc(100% - 10rpx);
				overflow: hidden; //超出的文本隐藏
				text-overflow: ellipsis; //用省略号显示
				white-space: nowrap; //不换行
			}

			.three {
				width: 100rpx;
				color: rgba(46, 205, 151, 1);
			}
		}

		.itemBox {
			margin: 10rpx auto 0rpx;
			width: 100%;
			// min-height: 300rpx;
			opacity: 1;
			border-radius: 10rpx;
			background: rgba(245, 246, 250, 1);
			padding: 12rpx 0rpx 12rpx 18rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			.itemContent {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 28rpx;
				font-weight: 400;
				letter-spacing: 0rpx;
				color: rgba(39, 39, 39, 1);

			}

			.itemTitle {
				width: 200rpx;
			}

			.itemValue {
				width: 400rpx;
			}
		}

		.btnBox {
			width: 100%;
			display: flex;
			justify-content: flex-end;
			align-items: center;
			color: #ffffff;
			margin-top: 20rpx;

			.lookClose,
			.lookCompleted,
			.review,
			.del,
			.Resubmit{
				min-width: 140rpx;
				// height: 58rpx;
				// line-height: 58rpx;
				border-radius: 30rpx;
				padding: 4rpx 12rpx;
				text-align: center;
				margin-left: 8rpx;
				// background: linear-gradient(270deg, rgba(136, 172, 255, 1) 0%, rgba(33, 101, 255, 1) 100%);
				border-radius: 30rpx 30rpx 30rpx 30rpx;
				border: 2rpx solid #286AFF;
				color: #286AFF;

			}

			.lookCompleted {}

			.del {
				// background: linear-gradient(270deg, rgba(249, 170, 170, 1) 0%, rgba(255, 108, 108, 1) 100%);
				border-radius: 30rpx 30rpx 30rpx 30rpx;
				border: 2rpx solid #FF6C6C;
				color: #FF6C6C;
			}
			.Resubmit {
				border-radius: 30rpx 30rpx 30rpx 30rpx;
				border: 2rpx solid #FF9D00;
				color: #FF9D00;
			}
		}
	}
</style>